#ifndef PRECEDENCE_H_
#define PRECEDENCE_H_

#include <string>
#include <cstdlib>

#include "./fila.hpp"
#include "./pilha.hpp"
#include "./error.h"

class mathExpression
{
public:
	
	mathExpression( );

	mathExpression( const char* );
	
	~mathExpression();
	
	void
	setExpr( const std::string );
	
	bool
	isValidExpression();
	
	std::string
	getPosFix( );
	
	double
	solveExpression();

protected:
	
	void
	setPrecedenceOp( const char );		
	
private:

	const bool
	isPrecedenceOperator( const char );
	
	const bool
	isOperator( const char );
	
	const unsigned short int
	getPrecedenceValue( const char );
	
	void
	throwException( std::string, const unsigned short int );
	
	std::string
	postFixatorPlus( std::string );
	
	const unsigned short int
	pauNoCu( const char& , const unsigned short int , const unsigned short int , const unsigned short int );
	
	const bool
	checkData( const char );
	
	const bool
	checkGreaterPrecedence( const char , const char);

	enum 
	operators {	openParentis  = '('  , 
				closeParentis = ')'  , 
				openCochetis  = '['  , 
				closeCochetis = ']'  , 
				openChavis    = '{'  , 
				closeChavis   = '}'	 ,
				PLUS 		  = '+'  ,
				MINUS		  = '-'  ,
				TIMES		  = '*'  ,
				DIV			  = '/'  ,
				POW			  = '^'   };


	bool
	validExpression;

	std::string
	expression;
	
	std::string
	postFixedExpr;

	pilha<char>*
	precedences;
	
	pilha<double>*
	parsedOperandis;
	
	pilha<char>*
	parsedOpereitors;
};



#endif /*PRECEDENCE_H_*/
